

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;


public class imageToBuffer {
	
	public static void imgIntBuffer(String path){
        try {
     	   //leo el archivo y lo paso al buffer de la imagen
     	   BufferedImage bimg = ImageIO.read(new File(path));
           StringBuffer buffimg = new StringBuffer();
            int itera=0;
            String hex;
            buffimg.append( " ").toString();
            for(int i = 0 ; i < bimg.getHeight() ; i++){
                for(int j = 0 ; j < bimg.getWidth(); j++){
             	   itera++;
                    int color = bimg.getRGB(j,i);
                    int r = (color >> 16 ) & 255;
                    int g = (color >> 8) & 255;
                    int b = (color) & 255;
                    
                    Color c = new Color(r,g,b);
                    hex =Integer.toHexString( c.getRGB() & 0x00ffffff );
                    //buffimg.append(hex + ", ");
                    System.out.println("rgb: "+ r + " " + g + " " + b + " hex: " + hex);
                }
            }
            //System.out.println("rgb: " + buffimg);
            System.out.println("iteraciones:" + itera);
            System.out.println("ancho: " + bimg.getWidth() + " pixels");
            System.out.println("alto: " + bimg.getHeight() + " pixels");                   
           
        } catch (IOException ex) {
            ex.printStackTrace();
        }
	}
    
   public static void main(String[] args) {
	   String path="C:\\Users\\moi\\Documents\\8.jpg";
	   imgIntBuffer(path);
	   	   
   }
}
